import { getToken } from '@/service/cookie'
export function connect (id:any) {
  const wsUrl:any = `${import.meta.env.VITE_API_WEBSCOKET}?course_id=${id}&token=${getToken('token')}`
  const ws:any = new WebSocket(wsUrl)
  console.log(ws)
}

export function onopen () {
  const data:any = '系统消息：建立连接成功'
  console.log(data)
}

export function oncloseWs () {
  console.log('连接关闭，定时重连')
}

export function onerror () {
  console.log('系统消息 : 出错了,请退出重试')
}

export function noticeStatus () {
  console.log('温馨提示')
}

export function sendMsg (msg:any) {
  console.log(msg)
}

export function messageLists (data:any) {
}
export function messageListsAll (data:any) {
}
export function shieldLsit (list:any) {
}

export function onmessage (e:any) {
  const data:any = JSON.parse(e.data)
  console.log(data.type, 888)
  switch (data.type) {
    case 'handShake':
      break
    case 'login':
      break
    case 'logout':
      break
    case 'message':
      break
    case 'system':
      break
    case 'notice':
      console.log('notice')
      break
    case 'forbidden':
      console.log('forbidden')
      break
    case 'shield':
      console.log('shield')
      break
    case 'check_live':
      console.log('check_live')
      break
    case 'live':
      if (data.msg === 'stop') {
        console.log('stop')
      } else if (data.msg === 'start') {
        console.log('start')
      } else if (data.msg === 'end') {
        console.log('end')
      }
      break
  }
}
